﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VirtualRink.Library
{
	public partial class Standing
	{
		//public static List<Standing> GetSeasonStandings(IRepository repository, Season season)
		//{
		//    List<Standing> items = new List<Standing>();
		//    IEnumerable<Game> games = repository.GetPlayedGames(season);
		//    Dictionary<Team, Standing> standings = new Dictionary<Team, Standing>();
			
		//    foreach (Game game in games)
		//    {
		//        if (!standings.ContainsKey(game.HomeTeam))
		//            standings.Add(game.HomeTeam, new Standing() { Season = season, Team = game.HomeTeam, League = season.League });
		//        if (!standings.ContainsKey(game.VisitingTeam))
		//            standings.Add(game.VisitingTeam, new Standing() { Season = season, Team = game.VisitingTeam, League = season.League });

		//        if (game.HomeGoals > game.VisitorGoals)
		//        {
		//            standings[game.HomeTeam].Wins++;
		//            standings[game.VisitingTeam].Losses++;
		//        }
		//        else if (game.HomeGoals < game.VisitorGoals)
		//        {
		//            standings[game.HomeTeam].Losses++;
		//            standings[game.VisitingTeam].Wins++;
		//        }
		//        else
		//        {
		//            standings[game.HomeTeam].Ties++;
		//            standings[game.VisitingTeam].Ties++;
		//        }
		//    }

		//    foreach (Team key in standings.Keys)
		//    {
		//        Standing standing = standings[key];
		//        standing.Points = standing.Wins * 2 + standing.Ties;
		//        items.Add(standing);
		//    }

		//    items.Sort(new StandingsComparer());

		//    for (int i = 0; i < items.Count; i++)
		//        items[i].Rank = i + 1;

		//    return items;
		//}
	}
}
